<?php
	class mroles extends Model {
		private $mTableName = 'GN_Roles';
	
		public function __construct() 
		{
			parent::Model();
			$this->load->database();
		}
		
		function CreateEstatus($nombre) 
		{

			$data = array( 
				'NombreRol'   => $nombre,
				'MenuRol'     =>1
				);
			
			$this->db->insert($this->mTableName, $data);
			return $this->LoadEstatusById($this->db->insert_id());
		}
		
		function UpdateEstatus($estatus) 
		{
			$nombre = $estatus->GetNombre();
			
			
			if (empty($nombre) )
				return false;
			
			$data = array(
				'NombreRol' => $nombre
								
			);
			
			$this->db->where('IdRol', $estatus->getIdEstatus());
        	$this->db->update($this->mTableName, $data);
			
			return true;
		}
		
		function LoadEstatusById($id_estatus) {
			$qresult = $this->db->get_where($this->mTableName, array('IdRol' => $id_estatus));

			if ($qresult->num_rows() == 0)
				return false;
	
			return new nata($qresult->row());
		}
		
		function LoadEstatus($start = false, $offset = false, $sortname = false, $sortorder = false) {
			
			
			if($offset != false)
				$this->db->limit($offset, $start);

			if($sortname != false && $sortorder != false) {
				$this->db->order_by($sortname, $sortorder);
			}
	
			$result = $this->db->get_where($this->mTableName);
	
			return $this->GetEstatusArrayFromQueryResult($result);
		}
		
		function GetCount() {
			return count($this->LoadEstatus());
		}
		
		function GetEstatusArrayFromQueryResult($result) {
			if ($result->num_rows() == 0)
				return false;
	
			$estatus_arr = array();
	
			foreach ($result->result() as $record) {
				$estatus_arr[] = new nata($record);
			}
	
			return $estatus_arr;
    	}
		

		
		function Delete($id_estatus) 
		{
			$return = $this->db->delete($this->mTableName, array('IdRol' => $id_estatus));
			return $return;
		}
	}
	
	class nata{
		private $mIdEstatus = 0;
		private $mNombre = "";
		
		
		function __construct($object) {
			$this->setIdEstatus($object->IdRol);
			$this->setNombre($object->NombreRol);
		
	
		}
		
		private function setIdEstatus($id_estatus) {
			$this->mIdEstatus = $id_estatus;
		}
		
		function getIdEstatus() {
			return $this->mIdEstatus;
		}
		
		function setNombre($nombre) {
			$this->mNombre = $nombre;
		}
		
		function getNombre() {
			return $this->mNombre;
		}	
		
	
	}
?>